package cn.doitedu.rtmk.mgmt.doit39_rtmk_management.controller;

import cn.doitedu.rtmk.mgmt.doit39_rtmk_management.pojo.Person;
import cn.doitedu.rtmk.mgmt.doit39_rtmk_management.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.*;
import java.util.List;

@RestController
public class PersonController {

    @Autowired  // 自动注入对象
    PersonService personService;

    @RequestMapping("/api/get_person_by_name")
    public List<Person> getPersons(String personName) throws SQLException {
        List<Person> personsByName = personService.getPersonsByName(personName);
        return personsByName;
    }


    @RequestMapping("/api/put_person")
    public String putPerson(@RequestBody Person person) throws SQLException {

        if(person == null || !StringUtils.hasText(person.getName())){
            return "参数不正确";
        }

        String  res = personService.putPerson(person);

        return res;

    }

}
